How to use the min() function in Postgresql